/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgLevelScreenSwitch
    {
        private readonly Dictionary<int, CfgLevelScreenSwitch> _dataMap;
        private readonly List<CfgLevelScreenSwitch> _dataList;


        public TbCfgLevelScreenSwitch(ByteBuf _buf)
        {
            //first read common data
            _TbCommonLevelScreenSwitch _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonLevelScreenSwitch(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgLevelScreenSwitch>(size * 3 / 2);
            _dataList = new List<CfgLevelScreenSwitch>(size);

            for (int i = 0; i < size; i++)
            {
                CfgLevelScreenSwitch _v;
                _v = CfgLevelScreenSwitch.DeserializeCfgLevelScreenSwitch(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgLevelScreenSwitch> DataMap => _dataMap;
        public IReadOnlyList<CfgLevelScreenSwitch> DataList => _dataList;

        public CfgLevelScreenSwitch Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgLevelScreenSwitch] config not found,id:" + key.ToString());

            return null;
        }

        public CfgLevelScreenSwitch GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "levelscreenswitch";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgLevelScreenSwitch LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgLevelScreenSwitch(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgLevelScreenSwitch
    {
        private CfgLevelScreenSwitch(ByteBuf _buf, _TbCommonLevelScreenSwitch _commonData)
        {
            Id = _buf.ReadInt();
            Name = _buf.ReadString();
            { int dataIndex = _buf.ReadInt() - 1; TargetPosition = _commonData._field0[dataIndex]; }
            TargetEntity = _buf.ReadInt();
            SwitchType = (LevelCameraSwitchType)(_buf.ReadInt());
            MoveTime = _buf.ReadInt();
            Duration = _buf.ReadInt();
            JumpId = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; EndService = _commonData._field1[dataIndex]; }
            IsSaveDelayService = _buf.ReadBool();

            PostInit();
        }

        internal static CfgLevelScreenSwitch DeserializeCfgLevelScreenSwitch(ByteBuf _buf, _TbCommonLevelScreenSwitch _commonData)
        {
            return new CfgLevelScreenSwitch(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 注释 ---- 编辑器专用
        /// </summary>
        private string Name { get; set; }
        /// <summary>
        /// 指定位置(x|y|z,单位cm)
        /// </summary>
        public IReadOnlyList<int> TargetPosition { get; private set; }
        /// <summary>
        /// 指定实体tag(要求唯一)
        /// </summary>
        public int TargetEntity { get; private set; }
        /// <summary>
        /// 1匀速2切屏
        /// </summary>
        public LevelCameraSwitchType SwitchType { get; private set; }
        /// <summary>
        /// 切屏时间(毫秒)
        /// </summary>
        public int MoveTime { get; private set; }
        /// <summary>
        /// 持续时间(毫秒)
        /// </summary>
        public int Duration { get; private set; }
        /// <summary>
        /// 下一个切屏配置id
        /// </summary>
        public int JumpId { get; private set; }
        /// <summary>
        /// 展示时执行服务
        /// </summary>
        public IReadOnlyList<int> EndService { get; private set; }
        /// <summary>
        /// 是否存储延迟服务
        /// </summary>
        public bool IsSaveDelayService { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonLevelScreenSwitch
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal _TbCommonLevelScreenSwitch(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
